home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 468 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.3 KB

  1. Path: engnews1.Eng.Sun.COM!taumet!clamage
  2. From: David Byrden <100101.2547@compuserve.com>
  3. Newsgroups: comp.std.c++
  4. Subject: Re: Generic Object Callbacks
  5. Date: 23 Feb 1996 17:55:28 GMT
  6. Organization: self-employed
  7. Approved: clamage@eng.sun.com (comp.std.c++)
  8. Message-ID: <4gkufu$akn@news.bridge.net>
  9. References: <pgpmoose.199602221531.14635@isolde.mti.sgi.com>
  10. NNTP-Posting-Host: taumet.eng.sun.com
  11. Mime-Version: 1.0
  12. Content-Type: text/plain; charset="us-ascii"
  13. Content-Transfer-Encoding: 7bit
  14. X-Nntp-Posting-Host: ppp-mia3-116.bridge.net
  15. X-Mailer: Mozilla 1.1N (Windows; I; 16bit)
  16. X-Lines: 31
  17. Content-Length: 1372
  18. Originator: clamage@taumet
  19.  
  20.  
  21. >>>
  22. What is needed is the ability to use member functions as callbacks
  23. without any constraint on the type of the object they are invoked on.
  24. This is possible in C++ only by using various implementation-dependent
  25. hacks to escape the type system, because the language does not provide
  26. any way to express such a construct.
  27. <<<
  28.  
  29.   The scheme presented by Richard Hickey in the C++ Report, Feb 95, 
  30. achieved this in what seemed to me an implementation-independent way. 
  31. Briefly; the creator of a functor would pass an object's and a function's 
  32. address to a template factory function; this would cause the 
  33. instantiation of various code, and return an object of a class Callback, 
  34. which would internally hold the addresses, the object address being 
  35. cast to void*.
  36.  
  37.  The Callback object had an operator() which would take the various 
  38. parameters expected for the callback, and pass them to another function 
  39. generated by the Factory specialisation. This function would cast the 
  40. void pointer to the appropriate type for the object, and complete the 
  41. call.
  42.  
  43.   No type information was shared between the caller and the called 
  44. modules, other than the declaration of various Callback classes and 
  45. associated functions. In fact, different Callback classes were required 
  46. to deal with functions having different numbers of parameters.
  47.  
  48.                                      David
  49.  
  50.  
  51.  
  52. [ To submit articles: Try just posting with your newsreader.
  53.               If that fails, use mailto:std-c++@ncar.ucar.edu
  54.   FAQ:    http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
  55.   Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
  56.   Comments? mailto:std-c++-request@ncar.ucar.edu
  57. ]
  58.